package com.hamizhong.iflowers.web.action.admin.prodgoods;

import net.sf.json.JSONObject;

import com.hamizhong.iflowers.service.IColorService;
import com.hamizhong.iflowers.service.IProductService;
import com.hamizhong.iflowers.service.IVarietyService;
import com.hamizhong.iflowers.utils.MyConstants;
import com.hamizhong.iflowers.web.base.MyBaseAjaxAction;
import com.hamizhong.iflowers.web.dto.IOPResultDto;
import com.hamizhong.iflowers.web.vo.ColorVO;
import com.hamizhong.iflowers.web.vo.IObjectVO;
import com.hamizhong.iflowers.web.vo.ProductVO;
import com.hamizhong.iflowers.web.vo.VarietyVO;

public class AjaxAddProductAction extends MyBaseAjaxAction {

	private IProductService iProductService = null;
	private IVarietyService iVarietyService = null;
	private IColorService iColorService = null;
	
	public IProductService getiProductService() {
		return iProductService;
	}
	public void setiProductService(IProductService iProductService) {
		this.iProductService = iProductService;
	}
	public IVarietyService getiVarietyService() {
		return iVarietyService;
	}
	public void setiVarietyService(IVarietyService iVarietyService) {
		this.iVarietyService = iVarietyService;
	}
	public IColorService getiColorService() {
		return iColorService;
	}
	public void setiColorService(IColorService iColorService) {
		this.iColorService = iColorService;
	}
	
	@Override
	protected JSONObject doRequest() {
		logger.info("...invoke...AjaxQueryProductAction...");
		String productName = getRQ().getParameter("productName");
		//String productId = getRQ().getParameter("productId");
		String varietyId = getRQ().getParameter("varietyId");
		String colorId = getRQ().getParameter("colorId");
		String sortId = getRQ().getParameter("sortId");
		String remarks = getRQ().getParameter("remarks");
		IOPResultDto<IObjectVO> resultDto = new IOPResultDto<IObjectVO>();
		ProductVO productVO = new ProductVO();
		productVO.setProductName(productName);
		productVO.setProductId(0);
		VarietyVO varietyVO = new VarietyVO();
		varietyVO.setVarietyId(varietyId);
		ColorVO colorVO = new ColorVO();
		colorVO.setColorId(colorId);
		productVO.setVarietyVO(varietyVO);
		productVO.setColorVO(colorVO);
		productVO.setSortId(Integer.valueOf(sortId));
		productVO.setRemarks(remarks);
		resultDto = iProductService.addProduct(productVO);
		JSONObject jo = new JSONObject();
		if(resultDto.isSuccess()) {
			jo.put("result", MyConstants.AJAX_SUCCESS);
		}else {
			jo.put("result", MyConstants.AJAX_FAILED_ALERT);
			jo.put("msg", resultDto.getErrorMSG());
		}
		return jo;
	}

}
